import request from "@/utils/request";

export function formatDate (date) {
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const hours = String(date.getHours()).padStart(2, '0')
  const minutes = String(date.getMinutes()).padStart(2, '0')
  const seconds = String(date.getSeconds()).padStart(2, '0')
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
export function getCTime () {
  const now = new Date()
  return formatDate(now)
}
export function handleClose (done,dialogVisible,confirm){
  confirm('确认关闭？')
      // eslint-disable-next-line no-unused-vars
      .then(_ => {
        dialogVisible=false
        done()
      })
      // eslint-disable-next-line no-unused-vars
      .catch(_ => {})
}
export function refresh(loading,message){
  const loadingMessage = loading({
    lock: true,
    text: 'Loading',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  });
  setTimeout(() => {
    loadingMessage.close();
    message({
      message: '数据已更新',
      center: true
    });
  }, 2000);
}
export function submitCheck(form1,message){
  if (form1.riskLevel === ''){
    message.error("风险等级不能为空！！")
    return
  }

  if (form1.riskLevel === '等级0' ){
    request.get('http://localhost:4009/admin/pass', {
      params: {
        postId:form1.postId,
        examine:'人工审核',
        currentStatus:form1.status,
        riskLevel: form1.riskLevel
      }
    }).then(res => {
      console.log(res)
      if (res.status !== 200){
        message.error(res.message)
      }else {
        message.success(res.message)
        /*this.loadPage("admin");*/
      }
    })
  }else {
    request.get('http://localhost:4009/admin/reject', {
      params: {
        postId: form1.postId,
        examine: '人工审核',
        currentStatus: form1.status,
        riskLevel: form1.riskLevel
      }
    }).then(res => {
      console.log(res)
      if (res.status !== 200) {
        message.error(res.message)
      } else {
        message.success("驳回成功！")
       /* this.loadPage("admin");*/
      }
    })

  }
}
